package com.ruoyi.web.controller.applet;

import com.ruoyi.applet.appletReceivingAddress.domain.AppletReceivingAddress;
import com.ruoyi.applet.appletReceivingAddress.service.IAppletReceivingAddressService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小程序用户收货地址Controller
 * @author ruoyi
 * @date 2024-12-17
 */
@Controller
@RequestMapping("/applet/appletReceivingAddress")
public class AppletReceivingAddressController extends BaseController {
    
    private final String prefix = "applet/appletReceivingAddress";
    
    @Resource
    private IAppletReceivingAddressService appletReceivingAddressService;
    
    @RequiresPermissions("applet:appletReceivingAddress:view")
    @GetMapping()
    public String appletReceivingAddress() {
        return prefix + "/appletReceivingAddress";
    }
    
    /**
     * 查询小程序用户收货地址列表
     */
    @RequiresPermissions("applet:appletReceivingAddress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppletReceivingAddress appletReceivingAddress) {
        startPage();
        List<AppletReceivingAddress> list = appletReceivingAddressService.selectAppletReceivingAddressList(appletReceivingAddress);
        return getDataTable(list);
    }
    
    /**
     * 导出小程序用户收货地址列表
     */
    @RequiresPermissions("applet:appletReceivingAddress:export")
    @Log(title = "小程序用户收货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppletReceivingAddress appletReceivingAddress) {
        List<AppletReceivingAddress> list = appletReceivingAddressService.selectAppletReceivingAddressList(appletReceivingAddress);
        ExcelUtil<AppletReceivingAddress> util = new ExcelUtil<AppletReceivingAddress>(AppletReceivingAddress.class);
        return util.exportExcel(list, "小程序用户收货地址数据");
    }
    
    /**
     * 新增小程序用户收货地址
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    
    /**
     * 新增保存小程序用户收货地址
     */
    @RequiresPermissions("applet:appletReceivingAddress:add")
    @Log(title = "小程序用户收货地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppletReceivingAddress appletReceivingAddress) {
        return toAjax(appletReceivingAddressService.insertAppletReceivingAddress(appletReceivingAddress));
    }
    
    /**
     * 修改小程序用户收货地址
     */
    @RequiresPermissions("applet:appletReceivingAddress:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        AppletReceivingAddress appletReceivingAddress = appletReceivingAddressService.selectAppletReceivingAddressById(id);
        mmap.put("appletReceivingAddress", appletReceivingAddress);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存小程序用户收货地址
     */
    @RequiresPermissions("applet:appletReceivingAddress:edit")
    @Log(title = "小程序用户收货地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppletReceivingAddress appletReceivingAddress) {
        return toAjax(appletReceivingAddressService.updateAppletReceivingAddress(appletReceivingAddress));
    }
    
    /**
     * 删除小程序用户收货地址
     */
    @RequiresPermissions("applet:appletReceivingAddress:remove")
    @Log(title = "小程序用户收货地址", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(appletReceivingAddressService.deleteAppletReceivingAddressByIds(ids));
    }
}
